
var defaultData={

}

columns=[[
    {
        field : 'ck',
        checkbox : true
    },{
        field:'id',
        title:'序号',
        align : 'center',
        width:100,
        hidden : true
    },{
        field:'dictCode',
        title:'字典编码',
        align : 'center',
        width:200
    },{
          field:'dictValue',
          title:'字典值',
          align : 'center',
          width:200
    },{
        field:'dictLabel',
        title:'字典名称',
        align : 'center',
        width:200
    }
]];

$(function(){
    var p = $('#dictDataGrid').datagrid({
        url:'/evpDict/list',
        method:'get',
        columns: columns,
        rownumbers: true,
        pagePosition: 'bottom',
        pagination: true,
        pageList: [10,20,30,40,50],
        idField: 'id',
        pageSize:10,
        pageNumber: 1,
        striped: true,
        singleSelect:true
    }).datagrid('getPager');

    p.pagination({
        beforePageText: '第',
        afterPageText:'共{pages}页',
        displayMsg: '当前显示 {from} 到 {to}条记录 ,共{total}条记录'
    });

    $('#dictLabelCBBox').combobox({
        url:'/evpDict/list',
        method:'get',
        valueField:'dictLabel',
        textField:'dictLabel',
        hasDownArrow: false,
        panelHeight: 'auto',
        onChange:function(newValue,oldValue){
             if (newValue != null && newValue !== "") {
                  $('#dictLabelCBBox').combobox('reload','/evpDict/list/combobox?dictLabel='+newValue);
             }
             if (newValue ==="") {
                 $('#dictLabelCBBox').combobox('loadData', {});
                 $("#dictLabelCBBox").combobox('clear').combobox('loadData', {});
               }
        }
    });


    // 添加区域窗口
    $('#addDictWindow').window({
        title : '添加字典',
        width : 550,
        modal : true,
        shadow : true,
        closed : true,
        height : 350,
        resizable : false
    });

    // 使窗口居中显示
    $("#addDictWindow").window('center');
});

/*
    搜索字典
*/
function searchDictList(){
    var dictLabel=$('#dictLabelCBBox').combobox('getValue');
    $('#dictDataGrid').datagrid('reload',{
    	dictLabel: dictLabel
    });
}

/*
    打开添加字典
*/
function addDictWindowOpen(){
    $("#submitDictForm").show();
    $("#submitEditDictForm").hide();
    $('#addDictWindow').window('open');
}

/*
    打开编辑字典
*/
function editDictWindowOpen(){
    $("#submitEditDictForm").show();
    $("#submitDictForm").hide();
    $('#addDictWindow').window('open');

    var row=$('#dictDataGrid').datagrid('getSelected');
    $('#addDictForm').form('load',row);
}

/*
    提交添加的字典信息
*/
function submitDictForm(){
    var checkResult=false;

    checkResult=checkValidateForm($('#addDictForm'));
    if(checkResult){
        var dataJSON=convertFormDataToJson($("#addDictForm").find("input").serializeArray());
        delete dataJSON.id;

        apiDictManageSubmitDictForm(JSONToStr(dataJSON),function(res){
            if(res.status==200){
                var tip="<span style='height=20px;line-height:20px;'><img src='js/jquery-easyui-1.7.0/themes/icons/ok.png'/><span style='margin-left:10px'>"+res.message+"</span></span>"
                messager('成功',tip,4000,'info');

                $('#dictDataGrid').datagrid('reload');
                $('#addDictWindow').window('close');
                clearDictForm();
            }else{
                var tip="<span style='height=20px;line-height:20px;'><img src='js/jquery-easyui-1.7.0/themes/icons/no.png'/><span style='margin-left:10px'>"+res.message+"</span></span>"
                messager('失败',tip,4000,'info');
            }

        });
    }
}

/*
    提交编辑的字典信息
*/
function submitEditDictForm(){
    var checkResult=false;

    checkResult=checkValidateForm($('#addDictForm'));

    if(checkResult){
        var dataStr=convertFormDataToJsonStr($("#addDictForm").find("input").serializeArray());

        apiDictManageSubmitEditDictForm(dataStr,function(res){
            if(res.status==200){
                var tip=getMessagerTip("ok",res.message);
                messager('成功',tip,4000,'info');

                $('#dictDataGrid').datagrid('reload');
                $('#addDictWindow').window('close');
                clearDictForm();
            }else{
                var tip=getMessagerTip("no",res.message);
                messager('失败',tip,4000,'info');
            }
        });
    }
}

/*
    删除字典
*/
function remoceDict(){
    $.messager.confirm('确认','您确认想要删除该字典吗？',function(r){
        if (r){
            var dictRow=$('#dictDataGrid').datagrid('getSelected');
            var dictId=dictRow.id;
            apiDictManageRemoveDict(dictId,function(res){
                if(res.status==200){
                    var tip=getMessagerTip("ok",res.message);
                    messager('成功',tip,4000,'info');

                    $('#dictDataGrid').datagrid('reload');
                }else{
                    var tip=getMessagerTip("no",res.message);
                    messager('失败',tip,4000,'info');
                }
            });
        }
    });
}

/*
    清空字典表单
*/
function clearDictForm(){
    $('#addDictForm').form('clear');
}